<template>
  <div class="l-rblock l-form-viewer" style="padding: 8px">
    <el-form :model="formData" :rules="rules" size="mini" labelPosition="right" labelWidth="80px" ref="form">
      <div class="l-auto-window only-tabs">
        <el-tabs v-model="activeName" type="card">
          <el-tab-pane class="l-tabs-container" :label="$t('主表信息')" name="tab0">
            <el-row :gutter="0">
              <div class="l-rblock">
                <el-col v-if="lr_formLookAuth('lr_base_file_f_Name')" :span="24">
                  <el-form-item :label="$t('名称')" prop="lr_base_file_f_Name">
                    <el-input :disabled="
                        !lr_formEditAuth('lr_base_file_f_Name', isReadOnly)
                      " v-model="formData.lr_base_file_f_Name" :placeholder="$t('请输入')">
                    </el-input>
                  </el-form-item>
                </el-col>
                <el-col v-if="lr_formLookAuth('lr_base_file_f_Keyword')" :span="24">
                  <el-form-item :label="$t('关键字')" prop="lr_base_file_f_Keyword">
                    <el-input :disabled="
                        !lr_formEditAuth('lr_base_file_f_Keyword', isReadOnly)
                      " v-model="formData.lr_base_file_f_Keyword" :placeholder="$t('请输入')">
                    </el-input>
                  </el-form-item>
                </el-col>
                <el-col v-if="lr_formLookAuth('lr_base_file_f_FileId')" :span="24">
                  <el-form-item :label="$t('文件')" prop="lr_base_file_f_FileId">
                    <l-upload :disabled="
                        !lr_formEditAuth(
                          'lr_base_file_f_FileId',
                          false || isReadOnly
                        )
                      " :accept="appConfig.file.accept" v-model="formData.lr_base_file_f_FileId"
                      :placeholder="$t('请输入')" />
                  </el-form-item>
                </el-col>
              </div>
            </el-row>
          </el-tab-pane>
        </el-tabs>
      </div>
    </el-form>
  </div>
</template>
<script>
const api = window.$api.system.file;

export default {
  props: {
    isReadOnly: {
      type: Boolean,
      default: false,
    },
  },
  data() {
    return {
      moduleCode: "oa_file",
      activeName: "tab0",
      formData: {
        lr_base_file_f_FileId: "", // 文件
        lr_base_file_f_Name: "", // 名称
        lr_base_file_f_Keyword: "", // 关键字
      },
      rules: {
        lr_base_file_f_Name: [{ required: true, message: this.$t("请输入名称") }],
        lr_base_file_f_FileId: [{ required: true, message: this.$t("请上传文件") }],
      },
      folder: "",
    };
  },
  computed: {},
  methods: {
    init(wfParams) {
      if (wfParams && wfParams.folder) {
        this.folder = wfParams.folder;
      }
    },
    // 重置表单
    resetForm() {
      this.$formClear(this.$refs.form);
      this.activeName = "tab0";
    },
    // 校验表单
    async validateForm() {
      if (!(await this.$formValidateWraper(this.$refs.form))) {
        return false;
      }

      return true;
    },
    getPrintData() {
      return {
        dep: this.$t('我是一个测试数据')
      }
    },

    // 设置表单数据
    setForm(data) {
      console.log(data, "setForm");
      this.$setFormData(this.formData, data, "lr_base_file");
    },
    // 获取表单数据
    getForm() {
      return this.$getFormData(this.formData, "lr_base_file");
    },

    async loadFormData({ keyValue /*,params,node*/ }) {
      //  keyValue 流程中相当于流程processId,params 传递参数,node 流程节点
      const data = await this.$awaitWraper(api.getByWF(keyValue));
      if (data) {
        this.setForm(data);
        return true;
      } else {
        return false;
      }
    },

    async saveForm({ keyValue, isEdit /*,code,node*/ }) {
      // isEdit 是否更新数据, keyValue 流程中相当于流程processId,code 表示流程中的操作码,node 流程节点
      const postData = this.getForm();

      if (isEdit) {
        // 编辑
        return true; //await this.$awaitWraper(api.update(keyValue, postData));
      } else {
        // 新增
        postData.f_Id = postData.f_FileId;
        postData.F_FolderId = this.folder;
        return await this.$awaitWraper(api.add(postData));
      }
    },
  },
};
</script>
